local function lobby_voting(survivors)
   local formspec =
   'size[12,7]'..
   'no_prepend[]'..
   'bgcolor[#080808BB;true]'..
   'textarea[1,1.5;11,6;;;Who dun it? make your pick. These players are on this map:'..
   '\n'..survivors..
   '\nYou can see the list of survivors at any time by using the /survivors command.'..
   '\nVote to kick the traitor with /kick <playername>, use skip to skip voting.]'..
   'button_exit[4.5,5;3,1;go;Discuss]'
   return formspec
end

minetest.register_node('lobby:corpse', {
   description = 'Corpse',
   drawtype = 'mesh',
   mesh = 'corpse.obj',
   tiles = {'lobby_corpse.png', 'lobby_blood.png'},
   use_texture_alpha = true,
   groups = {breakable=1, not_in_creative_inventory=1},
   paramtype = 'light',
   paramtype2 = 'facedir',
   selection_box = {
      type = 'fixed',
      fixed = {-.6, -.5, -.6, .6, -.2, .6}, -- Right, Bottom, Back, Left, Top, Front
   },
   collision_box = {
      type = 'fixed',
      fixed = {-.6, -.5, -.6, .6, -.2, .6}, -- Right, Bottom, Back, Left, Top, Front
   },
   on_rightclick = function(pos, node, clicker, itemstack)
      local name = clicker:get_player_name()
      local map_id = lobby.game[name]
      if map_id ~= 'lobby' then
         minetest.remove_node(pos)
         local game_data = lobby.savedata.data[map_id]
         local game_pos = game_data['level_pos']
         local survivors = lobby.players_on_level(map_id)
         lobby.votes[map_id] = 0
         for _, player in pairs(minetest.get_connected_players()) do
            local rname  = player:get_player_name()
            if lobby.game[rname] == map_id then
               lobby.voted[rname] = false
               player:set_physics_override({speed=0})
               minetest.chat_send_player(rname, minetest.colorize('#FF0000', 'Somebody discovered a corpse!'))
               minetest.show_formspec(rname, 'lobby:voting', lobby_voting(survivors))
               player:setpos({x=game_pos.x+(math.random(-3,3)),y=game_pos.y,z=game_pos.z+(math.random(-3,3))})
            end
         end
      end
   end,
})

minetest.register_node('lobby:emergency_button', {
   description = 'Emergency Button',
   drawtype = 'mesh',
   mesh = 'button.obj',
   tiles = {'button_gery.png', 'button_red.png'},
   --use_texture_alpha = true,
   groups = {breakable=1},
   paramtype = 'light',
   paramtype2 = 'facedir',
   selection_box = {
      type = 'fixed',
      fixed = {-.6, -.5, -.6, .6, -.2, .6}, -- Right, Bottom, Back, Left, Top, Front
   },
   collision_box = {
      type = 'fixed',
      fixed = {-.6, -.5, -.6, .6, -.2, .6}, -- Right, Bottom, Back, Left, Top, Front
   },
   on_rightclick = function(pos, node, clicker, itemstack)
      local name = clicker:get_player_name()
      local map_id = lobby.game[name]
      local game_data = lobby.savedata.data[map_id]
      local game_pos = game_data['level_pos']
      local survivors = lobby.players_on_level(map_id)
      lobby.votes[map_id] = 0
      for _, player in pairs(minetest.get_connected_players()) do
         local rname  = player:get_player_name()
         if lobby.game[rname] == map_id then
            lobby.voted[rname] = false
            player:set_physics_override({speed=0})
            minetest.chat_send_player(rname, minetest.colorize('#FF0000', name..' called an emergency meeting!'))
            minetest.show_formspec(rname, 'lobby:voting', lobby_voting(survivors))
            player:setpos({x=game_pos.x+(math.random(-3,3)),y=game_pos.y,z=game_pos.z+(math.random(-3,3))})
         end
      end
   end,
})
